package com.zlc.workflow.flow.node;


import com.zlc.common.common.exception.WorkflowException;
import com.zlc.workflow.flow.Node;
import com.zlc.workflow.flow.errorcontext.ErrorContext;
import com.zlc.workflow.flow.errorcontext.WindLocalError;
import com.zlc.workflow.message.MessageHelper;

import static com.zlc.workflow.message.ErrorCode.*;

/**
 * @author zhanglei
 */
abstract class AbstractNode extends Node {


    void pathToSameNowNode(String to,String nowNodeId,String path){
        if(to.equals(nowNodeId)){
            ErrorContext errorContext = WindLocalError.get();

            errorContext.code(XML_PATH_LOOP)
                    .errorMsg(MessageHelper.getMsg(XML_PATH_LOOP,path));
            errorContext.processBuilderError()
                    .errorValue(new String[]{to,path});

            throw new WorkflowException(MessageHelper.getMsg(XML_PATH_LOOP,path));
        }
    }


    void pathToNotFound(boolean exists,String[] errorValue,String path){
        if(!exists){
            ErrorContext errorContext = WindLocalError.get();

            errorContext.code(XML_PATH_TO_NULL)
                    .errorMsg(MessageHelper.getMsg(XML_PATH_TO_NULL,path));
            errorContext.processBuilderError()
                    .errorValue(errorValue);
            throw new WorkflowException(MessageHelper.getMsg(XML_PATH_TO_NULL,path));
        }
    }
}
